#include<stdio.h>
#include<stdlib.h>
#include<string.h>

/*
    About LinkList: insert, remove, change, create
    now we create list with no head-node
*/

#define Elemtype int
#define MAXLEN 100

typedef struct node{
    Elemtype data;
    // int len;//list length
    struct node *next;
}Node, *Linklist;

void Createlist_nohead(Linklist L, int n) {
    Node *p, *q;
    p = L;
    Elemtype data;
    // L = (Node*)malloc(n * sizeof(Node));
    if(n <= 0 || n > MAXLEN) {
        printf("input length is error!");
        return;
    }
    printf("input data:\n");
    for(int i = 0; i < n; i++) {
        scanf("%d", &data);
        // InsertBack(&L, data);
    }
    printf("create success!");
}

//get list length;
int listLen(Linklist L) {
    Node *p;
    int length = 0;
    p = L;
    while(p != NULL) {
        length++;
        p = p->next;
    }
    return length;
}

void InsertFront(Linklist *L, Elemtype data) {

}

// void InsertBack(Linklist *L, Elemtype data) {
//     int len = listLen(*L);
//     Node *p, *q;
//     p = *L;
//     if(len == 0) {
//         p = (Node*)malloc(sizeof(Node));
//         p->next = NULL;
//         p->data = data;
//         return;
//     }
//     //get lastnode
//     Node *tail = *L;
//     while(tail->next != NULL) {
//         tail = tail->next;
//     }
//     //insert
//     q = (Node*)malloc(sizeof(Node));
//     q->next = NULL;
//     q->data = data;
//     tail->next = q;
// }

void printLIst_sq(Linklist L) {
    Node *p = L;
    if(L == NULL)
        printf("list is empty!\n");
    printf("list is below:\n");
    while(p) {
        printf("%d ", p->data);
        p = p->next;
    }
}

int main(int argc, char const *argv[])
{
   int n;
   Linklist L;
   printf("input n:\n");
   scanf("%d", &n);
   Createlist_nohead(L, n);
   printLIst_sq(&L);
    return 0;
}
